%% export cvs
RANGE=1;
DETECTOR=1;

printdata=[];
for i=1:length(event)
    event(i).range
    event(i).detector
    if event(i).range==RANGE && event(i).detector==DETECTOR
        temp=event(i).profile(:,1);
        temp=circshift(temp,-find(temp==min(temp)))';
        printdata=[printdata; [...
            event(i).MJD,...
            anint/2,...
            anint/2,...
            1000*event(i).freq,...
            1000*event(i).freqer/2,...
            1000*event(i).freqer/2,...
            event(i).rms,...
            event(i).rms/10,...
            event(i).rms/10,...
            temp]];            
    end
end

% view the contents of the file
dlmwrite(['S' num2str(DETECTOR) 'G' num2str(RANGE) '.csv'],printdata,'delimiter',',','precision', 6)
type S2G2.csv